package com.example.lcode.binary;

public class Question153 {

    public int findMin(int[] nums) {
       return findMin(nums, 0, nums.length - 1);
    }

    private int findMin(int[] nums, int left, int right) {
        if (right == left) {
            return nums[left];
        }
        if (right - left == 1) {
            return Math.min(nums[right], nums[left]);
        }
        int mid = (left + right) / 2;
        if (nums[left] < nums[mid] && nums[mid] < nums[right]
                || nums[left] > nums[mid] && nums[mid - 1] < nums[mid]) {
            return findMin(nums, left, mid - 1);
        } else {
            return findMin(nums, mid, right);
        }
    }

    public static void main(String[] args) {
        Question153 question153 = new Question153();
        int []arr = {3,1,2};
        int min = question153.findMin(arr);
        System.out.println(min);
    }

}
